﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using SIS.ENT;
using SIS.BLL;
using SIS.UI;

public partial class Teacher_Teacher_list : System.Web.UI.Page
{


    #region "Private Variabels"
    public Common _common = new Common();

    #endregion

    #region "Events"

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            _common.LoadSchoolDDL(ddlSchoolList, string.Empty);
            _common.LoadCountryCodeDDL(ddlCountry, string.Empty);
            _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.Text), string.Empty);
            ddlSchoolList.Text = System.Configuration.ConfigurationManager.AppSettings["SchoolKeyDefault"].ToString();

            TeacherProfileTableList lList = new TeacherProfileTableList();
            lList = TeacherProfileTableManager.GetList(Convert.ToInt32(ddlSchoolList.SelectedValue));
            grvTeacherProfile.DataSource = lList;
            grvTeacherProfile.DataBind();

        }
    }

    protected void ddlSchoolList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void grvTeacherProfile_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvTeacherProfile.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = grvTeacherProfile.SelectedDataKey;
            int _TeacherProfileKey = Convert.ToInt32(_selectedDataKey[0]);
            int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);
            if (_TeacherProfileKey > 0 && _UserAccountKey > 0)
            {
                lblSelectedTeacherProfileKey.Text = _TeacherProfileKey.ToString();
                lblSelectedTeacherUserAccountKey.Text = _UserAccountKey.ToString();
            }
        }
    }

    protected void btnShowTeacherProfiles_Click(object sender, EventArgs e)
    {
        //if (grvTeacherProfile.SelectedIndex >= 0)
        //{
        //    DataKey _selectedDataKey = grvTeacherProfile.SelectedDataKey;
        //    int _TeacherProfileKey = Convert.ToInt32(_selectedDataKey[0]);
        //    int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);
        //    if (_TeacherProfileKey > 0 && _UserAccountKey > 0)
        //    {
        //        lblSelectedTeacherProfileKey.Text = _TeacherProfileKey.ToString();
        //        lblSelectedTeacherUserAccountKey.Text = _UserAccountKey.ToString();
        //    }
        //}

        int _schoolKey = Convert.ToInt32(ddlSchoolList.SelectedValue);
        string _Name = txtName.Text;
        if (_Name.Equals(string.Empty))
        {
            _Name = "%";
        }
        else
        {
            _Name = "%" + _Name + "%";
        }
        string _Address = txtAddress.Text;
        if (_Address.Equals(string.Empty))
        {
            _Address = "%";
        }
        else
        {
            _Address = "%" + _Address + "%";
        }
        string _NRICNO = txtNRIC.Text;
        if (_NRICNO.Equals(string.Empty))
        {
            _NRICNO = "%";
        }
        else
        {
            _NRICNO = "%" + _NRICNO + "%";
        }
        Int16 _AddressType = -1;

        if (ddlAddressType.SelectedIndex >= 0)
        {
            _AddressType = Convert.ToInt16(ddlAddressType.SelectedValue);
        }

        Int16 _CountryCode = -1;

        if (ddlCountry.SelectedIndex >= 0)
        {
            _CountryCode = Convert.ToInt16(ddlCountry.SelectedValue);
        }

        Int16 _CityCode = -1;

        if (ddlCity.SelectedIndex >= 0)
        {
            _CityCode = Convert.ToInt16(ddlCity.Text);
        }


        int _DistrictCode = -1;

        if (ddlDistrict.SelectedIndex >= 0)
        {
            _DistrictCode = Convert.ToInt32(ddlDistrict.Text);
        }

        TeacherProfileTableList lList = new TeacherProfileTableList();
        lList = TeacherProfileTableManager.GetList(_schoolKey, _Name, _Address, _NRICNO, _AddressType, _CountryCode, _CityCode, _DistrictCode);
        grvTeacherProfile.DataSource = lList;
        grvTeacherProfile.DataBind();
    }

    protected void btnAddNewTeacher_Click(object sender, EventArgs e)
    {
        Response.Redirect("teacherentry.aspx");
    }

    protected void grvTeacherProfile_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int TeacherProfileKey = Convert.ToInt32(grvTeacherProfile.DataKeys[1].Value);
        int UserAccountkey = Convert.ToInt32(grvTeacherProfile.DataKeys[e.RowIndex].Value);

        TeacherProfileTableManager.Delete(UserAccountkey, Convert.ToInt32(ddlSchoolList.SelectedValue));
    }

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        _common.LoadDistrictCodeDDL(ddlDistrict, Convert.ToInt16(ddlCountry.Text), string.Empty);
        ddlDistrict_SelectedIndexChanged(sender, e);
    }

    protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlDistrict.SelectedIndex >= 0)
        {
            _common.LoadCityCodeDDL(ddlCity, Convert.ToInt32(ddlDistrict.Text), Convert.ToInt16(ddlCountry.Text), string.Empty);
            ddlCity.Items.Insert(0, new ListItem("ALL", "-1"));
        }
    }

    #endregion

    #region "Methods"

    #endregion

   
}